<!DOCTYPE html>
<html>
<head>
    <title>登入</title>
    <#include "/common/include_header.ftl">
</head>
<body>

    <#include "/common/include_top.ftl">

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li><a href="login">登入</a></li>
                <li class="layui-this">注册</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <#--<form method="post">-->
                            <div class="layui-form-item">
                                <label for="L_email" class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="email" name="email"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">将会成为您唯一的登入名</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_username" class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="uname" name="username"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="pwd" name="pass"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="repwd" name="repass"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <button onclick="doRegister()" class="layui-btn" lay-filter="*">立即注册</button>
                            </div>

                        <#--</form>-->
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<#include "/common/include_footer.ftl">
<#include "/common/include_js.ftl">

<script type="text/javascript"  charset='utf-8' >
    function doRegister() {
        var uname = $("#uname").val();
        var email = $("#email").val();
        var pwd = $("#pwd").val();
        var repwd = $("#repwd").val();

        if (pwd != repwd) {
            layer.msg('两次密码不一样', {icon: 2});
            $("#pwd").focus();
        } else if(pwd.length <6 || pwd.length >16) {
            layer.msg('密码长度不合理', {icon: 2});
            $("#pwd").focus();
        } else {
            $.ajax({
                url: "doReg",
                type: "post",
                dataType: "json",
                data: {
                    "uname": uname,
                    "email": email,
                    "pwd": pwd
                },
                success: function (rd) {
                    if (rd.suc) {
                        layer.msg('注册成功', {icon: 1});
                        $.ajax({
                            url: 'doLogin',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                email: email,
                                pwd: pwd
                            },
                            success: function (rd) {
                                if (rd.suc) {
                                    window.location.href = "${basePath}" + "/user/index";
                                }
                            }
                        })
                    } else {
                        layer.msg(rd.msg, {icon: 2});
                    }
                }

            })
        }
    }

    function tip() {
        layer.open({
            title: '在线调试'
            ,content: '可以填写任意的layer代码'
        });
    }

</script>
</body>
</html>